package com.fcmeditech.AsianSexyGirls.File;

import java.io.File;
import android.content.Context;

public class FileCache {  
    
    private File cacheDir;
    //************Create a GirlList Folder******************//
    public FileCache(Context context){
        //Find the dir to save cached images
        if (android.os.Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED))//--Check whether or not the media is present and mounted at its mount point with read/write access.
            cacheDir=new File(android.os.Environment.getExternalStorageDirectory(),"GirlList");//--->Create a "GirlList" Folder in SD Card
        else
            cacheDir=context.getCacheDir();//Returns the absolute path to the application specific cache directory on the filesystem
        if(!cacheDir.exists())
            cacheDir.mkdirs();//Creates the directory named by the trailing filename of this file, including the complete directory path required to create this directory. 


    }
 /**
  * 
  * @param url
  * @return
  */
    public File getFile(String url){
        //I identify images by hashcode. Not a perfect solution, good for the demo.
        String filename=String.valueOf(url.hashCode());//valueOf:Converts the specified integer to its string representation
        File f = new File(cacheDir, filename);
        return f;
        
    }
    
    public void clear(){
        File[] files=cacheDir.listFiles();
        for(File f:files)
            f.delete();//-->Deletes this file. Directories must be empty before they will be deleted. 


    }

}